package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.StockoutMapper;
import com.zld.smarket.dto.StockinList;
import com.zld.smarket.dto.StockoutList;
import com.zld.smarket.pojo.Stockout;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.StockoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockoutServiceImpl implements StockoutService {
    @Autowired
    private StockoutMapper stockoutMapper;

    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<StockoutList> stockoutLists = stockoutMapper.selectAllAndPage(page,limit);
        Long count = stockoutMapper.countStockout();
        return new ResponseData(stockoutLists,count);
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<StockoutList> stockoutLists =  stockoutMapper.search(s,page,limit);
        Long count = stockoutMapper.countStockout();
        return new ResponseData(stockoutLists,count);
    }

    @Override
    public Long selectbyno(Long stockoutNo) {
        return stockoutMapper.countbyno(stockoutNo);
    }

    @Override
    public Integer addStockout(Stockout stockout) {
        int j=0;
        j=stockoutMapper.insert(stockout);
        return j;
    }

    @Override
    public Integer reduceSurplus(Long stockoutId, Long shelvesonNum) {
        return stockoutMapper.reduceSurplus(stockoutId,shelvesonNum);
    }


}
